using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Battle_PlayerGrazeBox : MonoBehaviour
{
	[SerializeField]
	private Animator GrazeboxAnimator;

	[SerializeField]
	private List<GameObject> BulletsInHolding = new List<GameObject>();

	private void Start()
	{
		((MonoBehaviour)this).StartCoroutine(IdleTPGain());
	}

	private void OnTriggerEnter2D(Collider2D other)
	{
		if (((Component)other).gameObject.tag == "Battle_Bullet" && !BulletsInHolding.Contains(((Component)other).gameObject) && !Battle_PlayerSoul.Instance.DamageCooldown)
		{
			BulletsInHolding.Add(((Component)other).gameObject);
			BattleSystem.PlayBattleSoundEffect(BattleSystem.Instance.SFX_graze, 0.5f);
			if ((Object)(object)((Component)other).GetComponent<Bullet_Generic>() != (Object)null)
			{
				BattleSystem.Instance.AddTP(1);
			}
			else
			{
				MonoBehaviour.print((object)"Error whilst grazing! Bullet_Generic not found in collider?");
			}
			GrazeboxAnimator.Play("battlegrazebox_graze", -1, 0f);
		}
	}

	private void OnTriggerExit2D(Collider2D other)
	{
		if (((Component)other).gameObject.tag == "Battle_Bullet" && BulletsInHolding.Contains(((Component)other).gameObject))
		{
			BulletsInHolding.Remove(((Component)other).gameObject);
		}
	}

	private void Update()
	{
		if (BulletsInHolding.Count > 0)
		{
			if (Battle_PlayerSoul.Instance.DamageCooldown)
			{
				BulletsInHolding.Clear();
				GrazeboxAnimator.SetBool("AnyBullets", false);
			}
			else
			{
				GrazeboxAnimator.SetBool("AnyBullets", true);
			}
		}
		else
		{
			GrazeboxAnimator.SetBool("AnyBullets", false);
		}
	}

	private IEnumerator IdleTPGain()
	{
		yield return (object)new WaitForSeconds(1f);
		if (BulletsInHolding.Count > 0)
		{
			BattleSystem.Instance.AddTP(1);
		}
		((MonoBehaviour)this).StartCoroutine(IdleTPGain());
	}
}
